<?php
/**
 * Created by PhpStorm.
 * User: shkj
 * Date: 2020/4/21
 * Time: 21:37
 */

namespace app\api\controller\v1;


use think\facade\Request;

class Goods extends Base
{
    private $obj;
    public function __construct() {

        $this->obj = model("Goods");
    }

    public function search(){
        $data = Request::get('query');
        $this->obj->search($data);
    }

    public function select(){
              $pagesize = Request::param('pagesize');
              $pagenum = Request::param('pagenum');
              
        $this->obj->select($pagesize,$pagenum);
    }

    public function cateSel(){
        $cate_id = Request::param('category_id');
        $this->obj->cateSel($cate_id);
    }

    public function typeSel(){
        $data = Request::param();
       if(isset($data['cid']) && !empty($data['cid']) && $data['cid']!='undefined'){
        $type_id = $data['cid'];
        $this->obj->typeSel($type_id);
       }elseif(isset($data['pid']) && !empty($data['pid']) && $data['pid']!='undefined' ){
        $category_id = $data['pid'];
        $this->obj->CateSel($category_id);
       }
       
    }

    public function propaganda(){
        $this->obj->propaganda();
    }

  

    public function detail(){
        $id = Request::param('id');

        // dump($id);
        $res = $this->obj->detail($id);
        if($res){
            return_json(200,'查询成功',$res);
        }else{
             return_json(400,'查询失败',false);
        }
    }

  public function adminDetail(){
        $id = Request::param('id');
      
        // dump($id);
        $this->obj->adminDetail($id);
    }

    public function delete(){
        $id = Request::param('id');
        $this->obj->del($id);
    }

    public function add(){
        $data = Request::post();
     
        $this->obj->add($data);
    }

    public function edit(){
        $id = Request::param('id');
        $data = Request::post();
        $this->obj->modify($id,$data);
    }

    public function status(){
        $id = Request::param('id');
        $on_sale = Request::param('on_sale');
        $this->obj->status($id,$on_sale);
    }
      public function pstatus(){
        $id = Request::param('id');
        $propaganda = Request::param('propaganda');
        $this->obj->pstatus($id,$propaganda);
    }

}